Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@rails/actioncable

Package Overview
Dependencies
Maintainers
8
Versions
127
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@rails/actioncable

WebSocket framework for Ruby on Rails.

  • 6.1.710
  • 6-1-stable
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
138K
decreased by-81.12%
Maintainers
8
Weekly downloads
 
Created

What is @rails/actioncable?

@rails/actioncable is a JavaScript client for Action Cable, which is a framework for handling WebSockets in Ruby on Rails applications. It allows you to create real-time features in your Rails applications by providing a way to communicate between the server and the client using WebSockets.

What are @rails/actioncable's main functionalities?

Establishing a WebSocket Connection

This code establishes a WebSocket connection to the specified URL. The `createConsumer` method is used to create a new consumer instance that will manage the WebSocket connection.

const cable = ActionCable.createConsumer('ws://cable.example.com');

Subscribing to a Channel

This code subscribes to a channel named 'ChatChannel'. The `received` function is called whenever data is broadcasted to the channel. In this example, it simply logs the received data to the console.

const subscription = cable.subscriptions.create('ChatChannel', {
  received(data) {
    console.log('Received:', data);
  }
});

Sending Data to the Server

This code sends data to the server through the WebSocket connection. The `send` method is used to transmit a message to the server, which can then be processed and broadcasted to other clients.

subscription.send({ message: 'Hello, World!' });

Unsubscribing from a Channel

This code unsubscribes from the 'ChatChannel'. The `unsubscribe` method is used to terminate the subscription and stop receiving data from the channel.

subscription.unsubscribe();

Other packages similar to @rails/actioncable

Keywords

FAQs

Package last updated on 23 Oct 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc